package Var1018;

public class Fourth {
    //5.汽车由发动机，轮胎，车架，底盘组成，
    //有外观，价格，油耗等属性
    //有启动，停止，鸣笛等方法。用oo的思
    //想定义汽车类，并测试。
    public static void main(String[] args) {
        Automobile d = new Automobile();
        d.brand = "大众帕斯特";
        d.price = 26;//单位万
        d.weight = 3;//单位吨
        d.vel = 0;
        d.show();
        d.drive();
        String a = d.brake();
        System.out.println(a);
        d.trumpet();
    }

    public static class Automobile {
        String brand;
        double price;
        double weight;
        double vel;
        String stop;
        boolean isDrive = true;

        public void show() {
            System.out.println("一辆价格为" + price + "万元，品牌是：" + brand + ",重量是" + weight + "吨，当前油量：" + vel + "升");
        }

        public boolean drive() {
            while (!(vel == 0)) {
                System.out.println("汽车正在行驶");
                vel--;
                isDrive = false;
            }
            System.out.println("汽车没油了，停止行驶");
            return isDrive;
        }

        public String brake() {
            if (isDrive) {
                stop = "有路人横穿马路，刹车";
            }
            return stop;
        }

        public void trumpet() {
            if (isDrive) {
                System.out.println("前方有行人，打喇叭");
            }
        }
    }
}
